package com.songqi.common.redis.lock;

import lombok.NonNull;
import org.springframework.data.redis.core.script.DigestUtils;
import org.springframework.data.redis.core.script.RedisScript;

/**
 * @description: 释放锁脚本类型。定义脚本内容和执行脚本后返回的对象类型
 * @author: songqi(13776346982)
 * @date: 2023/8/21 14:48
 */
public class UnlockRedisScript<T> implements RedisScript<T> {

    private final String script;

    private final Class<T> resultType;

    public UnlockRedisScript(String script, Class<T> resultType){
        this.script = script;
        this.resultType = resultType;
    }

    @NonNull
    @Override
    public String getSha1() {
        return DigestUtils.sha1DigestAsHex(this.getScriptAsString());
    }

    @Override
    public Class<T> getResultType() {
        return this.resultType;
    }

    @NonNull
    @Override
    public String getScriptAsString() {
        return this.script;
    }
}
